package com.yonyou.isv.demo.openapi.base.response;

import com.alibaba.fastjson.JSON;
import com.yonyou.isv.demo.openapi.base.exception.BusinessException;
import lombok.Data;

/**
 * 本类主要用于
 *
 * @author liuhaoi
 * @since Created At 2020/5/11 11:08 上午
 */
@Data
public class OpenApiResponse<T> {


    private Object code;

    private String message;

    private T data;

    public void check() {
        if (code instanceof Number && ((int) code == 0 || (int) code == 200)) {
            return;
        }

        if ("00000".equals(code) || "200".equals(code)) {
            return;
        }

        throw new BusinessException("open api response check failed, with response " + JSON.toJSONString(this));
    }
}
